﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace MTRC.ODMS.Web.SOM.CodeSetup
{
    public partial class FireLinkRestoreList : BasePage_SOM
    {

        /// <summary>
        /// bind data to datagrid
        /// </summary>
        private void BindData()
        {
            DataTable Table = MTRC.ODMS.DAL.SOM.CodeSetup.CDLine.GetLineList(this.LangCode);

            DataView View = Table.DefaultView;
            View.Sort = this.grdSearchResult.DataViewSortExpression;

            this.grdSearchResult.DataSource = View;
            this.grdSearchResult.DataBind();

            Table.Dispose();
            Table = null;
        }
        #region Set language

        private void SetLanguage()
        {
            this.btnAddNew.Text = GetLabel("SOM_AddNewlLine", false);
            this.lblSOMSLineSetup.Text = GetLabel("SOM_LineSetup", false);
        }

        void LineEnquiry_ChangeLanguage(object sender, EventArgs e)
        {
            SetLanguage();
            BindData();
        }
        
        #endregion

        /// <summary>
        /// If the selected
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool IsChecked(object obj)
        {
            bool isChekced = false;
            if (obj != null)
                isChekced = string.Compare(obj.ToString(), "True") == 0;
            return isChekced;
        }

        /// <summary>
        /// Page load event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grdSearchResult.PageSize = this.GridViewPageDefaultSize();
                SetLanguage();
                BindData();
            }
            else
            {
                this.IsServerChanged = true;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(LineEnquiry_ChangeLanguage);
            this.grdSearchResult.NeedDataBind += new APJ.Web.UI.WebControls.CommonGridView.NeedDataBindHandler(grdSearchResult_NeedDataBind);
        }

        /// <summary>
        /// for pager funciton
        /// </summary>
        protected void grdSearchResult_NeedDataBind()
        {
            BindData();
        }

        /// <summary>
        /// deal the edit event of gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grdSearchResult_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToUpper() == ("edit").ToUpper())
            {
                this.Response.Redirect("LineEntry.aspx?action=edit&SOMLineID=" + e.CommandArgument.ToString());
            }
        }

    }
}